//-----------------------------------------------------------------------------
/// STATE_INIT (Implementation)
//-----------------------------------------------------------------------------
START_STATE_CODE( STATE_SPLASHSCREEN )
{
    START_MESSAGE_HANDLER( MESSAGE_ENTER )
    {
		// GameInit();
		StateSplashScreenInit();
    }

    START_MESSAGE_HANDLER( MESSAGE_UPDATE )
    {		
		StateSplashScreenUpdate();
    }

    START_MESSAGE_HANDLER( MESSAGE_PAINT )
    {
		StateSplashScreenPaint(s_gBackBuffer);
    }

    START_MESSAGE_HANDLER( MESSAGE_EXIT )
    {
		// GameDestroy();
		StateSplashScreenExit();
    }

	START_MESSAGE_HANDLER( MESSAGE_HIDENOTIFY )
	{
		// GameHideNotify();
	}
}

static void StateSplashScreenInit()
{	
	try
	{
		s_imgBackBuffer = Image.createImage("/splash.png");
	}
	catch(Exception ex)
	{
		System.out.println("!!!! STATE_SPLASHSCREEN error");
	}
}

static void StateSplashScreenUpdate()
{
	if(s_iReleasedKey == CanvasKeys.SELECT)
	{
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
	}
	switch(s_iReleasedKey)
	{
		case CanvasKeys.NUM5:
		case CanvasKeys.SELECT:
			SwitchState(STATE_MAINMENU);
			break;
		default:
			break;
	}
}

static void StateSplashScreenPaint(Graphics g)
{
	int w = GetStringWidth(GetString(TEXT.INIT_PRESS_OK));
	
	g.drawImage(s_imgBackBuffer,0,0,0);
	try{
		if((System.currentTimeMillis() & (1<<9)) != 0)
		{
			DrawString(g, GetString(TEXT.INIT_PRESS_OK), (s_iWidth-w)/2, 250);
		}
	}
	catch(Exception ex)
	{
	}
}

static void StateSplashScreenExit()
{
	s_imgBackBuffer = null;
	System.gc();
	System.out.println("<<<<<<<<<<<<<<< StateSplashScreenExit >>>>>>>>>>>>>>>>");
}